﻿<UserControl x:Class="EQual.MainModule.Projects.Tasks.Views.TasksGridView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Models="clr-namespace:EQual.MainModule" 
    xmlns:WpfApplicationExperimental="clr-namespace:WpfApplicationExperimental;assembly=WpfApplicationExperimental"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" 
    xmlns:inf="clr-namespace:EQual.Infrastructure.Converters;assembly=EQual.Infrastructure"              >

    <UserControl.Resources >
        <!---->  
        <ObjectDataProvider x:Key="ProjectTypes" ObjectType="{x:Type Models:ProjectsProvider}" MethodName="GetProjectsTypes" />
        <ObjectDataProvider x:Key="ProjectStatusTypes" ObjectType="{x:Type Models:ProjectsProvider}" MethodName="GetProjectsStatusTypes" />
        <ObjectDataProvider x:Key="Employees" ObjectType="{x:Type Models:EmployeesProvider}" MethodName="GetEmployees" />
       <inf:DecimalToColorConverter x:Key="ProgressConverter" />
    </UserControl.Resources>
    <Grid>
        <dg:DataGrid  Name="dataGrid1"  
                      CanUserAddRows="True"
                      Background="Transparent" 
                      AutoGenerateColumns="False"
                      ItemsSource="{Binding Path=ItemsCollection}" SelectionChanged="dataGrid1_SelectionChanged" RowEditEnding="dataGrid1_RowEditEnding" Grid.ColumnSpan="2">
            
        <dg:DataGrid.Columns >
                <dg:DataGridTextColumn Binding="{Binding TaskId}" Header="Id" /> 
                <dg:DataGridTextColumn Binding="{Binding Title}" Header="Title"/>

                <dg:DataGridTemplateColumn Header="Starting Date" >
                <!-- editing template -->
        <dg:DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
                <dg:DatePicker
                           SelectedDate="{Binding Path=StartDate, Mode=TwoWay}"
                           BorderThickness="0"/>
            </DataTemplate>
        </dg:DataGridTemplateColumn.CellEditingTemplate>
        <!-- standard template -->
        <dg:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock>
                            <TextBlock.Text>
                                <Binding Path="StartDate"
                                   ConverterCulture="en-GB"
                                   StringFormat="{}{0:d}"/>
                            </TextBlock.Text>
                </TextBlock>
            </DataTemplate>
        </dg:DataGridTemplateColumn.CellTemplate>
        </dg:DataGridTemplateColumn>

        <dg:DataGridTemplateColumn Header="Ending Date" >
            <!-- editing template -->
            <dg:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <dg:DatePicker
                                   SelectedDate="{Binding Path=EndDate, Mode=TwoWay}"
                                   BorderThickness="0"/>
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellEditingTemplate>
            <!-- standard template -->
            <dg:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock>
                                    <TextBlock.Text>
                                        <Binding Path="EndDate"
                                           ConverterCulture="en-GB"
                                           StringFormat="{}{0:d}"/>
                                    </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellTemplate>
        </dg:DataGridTemplateColumn>
<!--
        <dg:DataGridComboBoxColumn SelectedValueBinding="{Binding ProjectType}"                                            
                                           SelectedValuePath="ProjectTypeId"
                                           DisplayMemberPath="name"
                                           Header="Project Type"
                                           ItemsSource="{Binding Source={StaticResource ProjectTypes}}">
            <dg:DataGridComboBoxColumn.EditingElementStyle>
                <Style TargetType="ComboBox">
                    <Setter Property="IsEditable" Value="True" />
                </Style>
            </dg:DataGridComboBoxColumn.EditingElementStyle>
        </dg:DataGridComboBoxColumn>
     -->
        <dg:DataGridComboBoxColumn SelectedValueBinding="{Binding ProjectStatusType}"                                            
                                           SelectedValuePath="ProjectStatusTypeId"
                                           DisplayMemberPath="name"
                                           Header="Task Status"
                                           ItemsSource="{Binding Source={StaticResource ProjectStatusTypes}}">
            <dg:DataGridComboBoxColumn.EditingElementStyle>
                <Style TargetType="ComboBox">
                    <Setter Property="IsEditable" Value="True" />
                </Style>
            </dg:DataGridComboBoxColumn.EditingElementStyle>
        </dg:DataGridComboBoxColumn>

        <dg:DataGridComboBoxColumn SelectedValueBinding="{Binding TaskOwnerId}"                                            
                                           SelectedValuePath="id"
                                           DisplayMemberPath="name"
                                           Header="Task Status"
                                           ItemsSource="{Binding Source={StaticResource Employees}}">
            <dg:DataGridComboBoxColumn.EditingElementStyle>
                <Style TargetType="ComboBox">
                    <Setter Property="IsEditable" Value="True" />
                </Style>
            </dg:DataGridComboBoxColumn.EditingElementStyle>
        </dg:DataGridComboBoxColumn>

        <dg:DataGridTemplateColumn Header="Progress" >
            <!-- editing template -->
            <dg:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding ProjectProgress}"/>
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellEditingTemplate>
            <!-- standard template -->
            <dg:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ProgressBar Value="{Binding TaskProgress}" />
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellTemplate>
        </dg:DataGridTemplateColumn>
        </dg:DataGrid.Columns>
        </dg:DataGrid>
        </Grid>
</UserControl>
